/****************************************************************************
**
** AnimationManager.h
**
** Copyright (C) August 2014 Hotride
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
*****************************************************************************
*/
//---------------------------------------------------------------------------
#ifndef AnimationManagerH
#define AnimationManagerH
//---------------------------------------------------------------------------
class TAnimationManager
{
private:
	DWORD m_AddressIdx[6];
	DWORD m_AddressMul[6];
	DWORD m_SizeIdx[6];

	PDWORD m_Data;
	int m_Width;
	int m_Height;

	WORD m_Color;

	ANIM_INDEX_HEADER m_DataIndex[0x0800];

	DWORD m_AddressAnimData;

	void GetAnimInformation(ANIM_FRAME_INFO &af, WORD ID, int Offset, BYTE &Frame);

	void ExecuteAnim(ANIM_FRAME &af, WORD ID, WORD Color, bool PartialHue, int &Offset, BYTE &Frame);

	bool TextAnimPixels(ANIM_FRAME_INFO &af, int &CheckX, int &CheckY);
	
	void Draw(TGameObject *obj, float X, float Y, float Z, bool &Mirror, int &Offset, BYTE &AnimIndex, WORD ID = 0x0000);
	
	bool TestPixels(TGameObject *obj, int X, int Y, int Z, bool &Mirror, int &Offset, BYTE &AnimIndex, WORD ID = 0x0000);

	void CalculateImageSize(TGameObject *obj);
public:
	TAnimationManager();
	~TAnimationManager() {}
	
	void InitAnimData(DWORD Address) {m_AddressAnimData = Address;}
	void Init(int idx, DWORD AddressIdx, DWORD AddressMul, DWORD SizeIdx)
	{
		m_AddressIdx[idx] = AddressIdx;
		m_AddressMul[idx] = AddressMul;
		m_SizeIdx[idx] = SizeIdx;
	}
	void InitBodyconv(PDWORD verdata, string fName);
	void Load(PDWORD verdata);

	void DrawCharacter(TGameObject *obj, float X, float Y, float Z);
	bool CharacterPixelsInXY(TGameObject *obj, int X, int Y, int Z);

	int GetItemAnimationIndex(WORD ID, int &CurrentIndex, bool &AnimateNext, WORD &Delay);

	ANIMATION_GROUPS GetGroupIndex(WORD ID);
};
//---------------------------------------------------------------------------
#endif